package com.tianzeculture.stagebao.activity.home.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.bean.BannerBean;
import com.tianzeculture.stagebao.bean.TuijianBean;
import com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2;
import com.tianzeculture.stagebao.util.Util;

import java.util.List;

import static com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2.PICTURE_URL;

/**
 * Created by Administrator on 2018/5/30 0030.
 */

public class MultiplePagerAdapter extends PagerAdapter {
    private Context context;
    private List<BannerBean> mList;

    public MultiplePagerAdapter(Context context, List<BannerBean> list) {
        super();
        this.context = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    /**
     * 页面宽度所占ViewPager测量宽度的权重比例，默认为1
     */
    @Override
    public float getPageWidth(int position) {
        return (float) 1;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = (View) object;
        ((ViewPager) container).removeView(view);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_home_viewpager_item, null);
        container.addView(view);
        ImageView imageView = view.findViewById(R.id.ivPager);
        Picasso.with(context).load(PICTURE_URL + mList.get(position).getBannerPic()).into(imageView);
        return view;
    }
}